<template>
  <div>
    <CustomTable
      :data-source="tableData"
      :columns="columns"
      @rowOption="rowOption"
      @handleSelectionChange="handleSelectionChange"
      pagination
      :total="total"
      @pageChange="pageChange"
    >
    </CustomTable>
  </div>
</template>

  <script>
import axios from "axios";

import CustomTable from "./table/CustomTable.vue";
export default {
  components: { CustomTable },
  data() {
    return {
      page: 1,
      total: 100,
      tableData: [],
      columns: [
        { type: "selection", label: "selection" },
        // { type: "date", label: "id", prop: "id" },
        // { type: "text", label: "游戏名称", prop: "gameName" },
        // { type: "text", label: "房间名称", prop: "roomName" },
        { type: "text", label: "玩家ID", prop: "playerId" },
        { type: "text", label: "金币", prop: "amount" },
        { type: "text", label: "类型", prop: "operateTypeName" },
        { type: "text", label: "地址", prop: "ipAddress" },
        { type: "date", label: "时间", prop: "createTime" },
        {
          width: '200px',
          type: "button",
          label: "操作",
          btnOption: [
            { type: "text", label: "编辑", icon: "el-icon-edit" },
            { type: "text", label: "删除", icon: "el-icon-delete" },
            { type: "text", label: "查看", icon: "el-icon-view", },
          ],
        },
      ],
      page: 1,
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      axios({
        method: "GET",
        url: "http://121.196.39.32/admin-facade/manage/queryGoldRecordPage",
        params: {
          page: this.page,
          size: 10,
          startTime: 1659668337301,
          endTime: 1660273137301,
          token: "a666c61f-b520-4881-a65b-624ea0019c06",
        },
      })
        .then((res) => {
          this.tableData = res.data.data.list;
          this.total = res.data.data.total;
          // console.log(this.tableData);
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    pageChange(page) {
      // console.log("当前页=", page);
      this.page = page;
      this.init(this.page);
    },
    rowOption(row, index, btn) {
      console.log(row, index, btn);
      if (btn === "编辑") console.log("edit");
      if (btn === "删除") console.log("detele");
      if (btn === "查看") console.log("show");
    },
    handleSelectionChange(value) {
      console.log("选中行数据", value);
    },
  },
};
</script>
<style scoped>
::v-deep .el-button--text .el-icon-delete span{
  color: red;
}
</style>